package com.ziyucoding.springboot.labs.lab4.concurrentdemo.example.singleton;

import com.ziyucoding.springboot.labs.lab4.concurrentdemo.annoations.ThreadSafe;

/**
 * 单例模式
 * 饿汉模式：单例实例在在类装载时进行创建
 * 饿汉模式的不足：类加载慢，引起性能问题，可能带来资源的浪费
 *
 * @author ziyucoding
 * @date 2022-10-26
 **/
@ThreadSafe
public class SingletonExample2 {

    /**
     * 单例
     */
    private static SingletonExample2 instance = new SingletonExample2();

    private SingletonExample2() {

    }

    /**
     * 获取实例
     *
     * @return SingletonExample2
     **/
    public static SingletonExample2 getInstance() {
        return instance;
    }
}
